package com.yanfan.zutai.service.impl;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.zutai.domain.BWorkOrder;
import com.yanfan.zutai.mapper.BWorkOrderMapper;
import com.yanfan.zutai.service.IBWorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 工单管理Service业务层处理
 *
 * @author ruoyi
 * @date 2021-02-27
 */
@Service
public class BWorkOrderServiceImpl implements IBWorkOrderService {
    @Autowired
    private BWorkOrderMapper bWorkOrderMapper;

    /**
     * 查询工单管理
     *
     * @param id 工单管理ID
     * @return 工单管理
     */
    @Override
    public BWorkOrder selectBWorkOrderById(Long id) {
        return bWorkOrderMapper.selectBWorkOrderById(id);
    }

    /**
     * 查询工单管理列表
     *
     * @param bWorkOrder 工单管理
     * @return 工单管理
     */
    @Override
    public List<BWorkOrder> selectBWorkOrderList(BWorkOrder bWorkOrder) {
        return bWorkOrderMapper.selectBWorkOrderList(bWorkOrder);
    }

    /**
     * 新增工单管理
     *
     * @param bWorkOrder 工单管理
     * @return 结果
     */
    @Override
    public int insertBWorkOrder(BWorkOrder bWorkOrder) {
        bWorkOrder.setCreateTime(DateUtils.getNowDate());
        // 生成19位的唯一id
        Snowflake snowflake = IdUtil.getSnowflake(6, 2);
        long id = snowflake.nextId();
        bWorkOrder.setId(id);
        return bWorkOrderMapper.insertBWorkOrder(bWorkOrder);
    }

    /**
     * 修改工单管理
     *
     * @param bWorkOrder 工单管理
     * @return 结果
     */
    @Override
    public int updateBWorkOrder(BWorkOrder bWorkOrder) {
        bWorkOrder.setUpdateTime(DateUtils.getNowDate());
        return bWorkOrderMapper.updateBWorkOrder(bWorkOrder);
    }

    /**
     * 批量删除工单管理
     *
     * @param ids 需要删除的工单管理ID
     * @return 结果
     */
    @Override
    public int deleteBWorkOrderByIds(Long[] ids) {
        return bWorkOrderMapper.deleteBWorkOrderByIds(ids);
    }

    /**
     * 删除工单管理信息
     *
     * @param id 工单管理ID
     * @return 结果
     */
    @Override
    public int deleteBWorkOrderById(Long id) {
        return bWorkOrderMapper.deleteBWorkOrderById(id);
    }
}
